<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,IE=9,chrome=1"><meta name="generator" content="MATLAB 2023a"><title>Example script how to use PIVlab from the commandline</title><style type="text/css">.rtcContent { padding: 30px; } .S0 { margin: 3px 10px 5px 4px; padding: 0px; line-height: 28.8px; min-height: 0px; white-space: pre-wrap; color: rgb(192, 76, 11); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 24px; font-weight: 400; text-align: left;  }
.S1 { margin: 2px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;  }
.CodeBlock { background-color: #F5F5F5; margin: 10px 0 10px 0; }
.S2 { border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S3 { margin: 10px 10px 9px 4px; padding: 0px; line-height: 21px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 14px; font-weight: 400; text-align: left;  }
.S4 { border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 4px 4px 0px 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S5 { border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 0px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S6 { border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S7 { margin: 3px 10px 5px 4px; padding: 0px; line-height: 20px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left;  }
.S8 { border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S9 { color: rgb(33, 33, 33); padding: 10px 0px 6px 17px; background: rgb(255, 255, 255) none repeat scroll 0% 0% / auto padding-box border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px; overflow-x: hidden; line-height: 17.234px;  }
/* Styling that is common to warnings and errors is in diagnosticOutput.css */.embeddedOutputsErrorElement {    min-height: 18px;    max-height: 550px;}
.embeddedOutputsErrorElement .diagnosticMessage-errorType {    overflow: auto;}
.embeddedOutputsErrorElement.inlineElement {}
.embeddedOutputsErrorElement.rightPaneElement {}
/* Styling that is common to warnings and errors is in diagnosticOutput.css */.embeddedOutputsWarningElement {    min-height: 18px;    max-height: 550px;}
.embeddedOutputsWarningElement .diagnosticMessage-warningType {    overflow: auto;}
.embeddedOutputsWarningElement.inlineElement {}
.embeddedOutputsWarningElement.rightPaneElement {}
/* Copyright 2015-2022 The MathWorks, Inc. *//* In this file, styles are not scoped to rtcContainer since they could be in the Dojo Tooltip */.diagnosticMessage-wrapper {    font-family: Menlo, Monaco, Consolas, "Courier New", monospace;    font-size: 12px;}
.diagnosticMessage-wrapper.diagnosticMessage-warningType {    color: var(--mw-color-matlabWarning);}
.diagnosticMessage-wrapper.diagnosticMessage-warningType a {    color: var(--mw-color-matlabWarning);    text-decoration: underline;}
.rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-warningType,.rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-warningType a {    color: var(--mw-color-matlabWarning) !important;}
.diagnosticMessage-wrapper.diagnosticMessage-errorType {    color: var(--mw-color-matlabErrors);}
.diagnosticMessage-wrapper.diagnosticMessage-errorType a {    color: var(--mw-color-matlabErrors);    text-decoration: underline;}
.rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-errorType,.rtcThemeDefaultOverride .diagnosticMessage-wrapper.diagnosticMessage-errorType a {    color: var(--mw-color-matlabErrors) !important;}
.diagnosticMessage-wrapper .diagnosticMessage-messagePart,.diagnosticMessage-wrapper .diagnosticMessage-causePart {    white-space: pre-wrap;}
.diagnosticMessage-wrapper .diagnosticMessage-stackPart {    white-space: pre;}
.embeddedOutputsTextElement,.embeddedOutputsVariableStringElement {    white-space: pre;    word-wrap:  initial;    min-height: 18px;    max-height: 550px;}
.embeddedOutputsTextElement .textElement,.embeddedOutputsVariableStringElement .textElement {    overflow: auto;}
.textElement,.rtcDataTipElement .textElement {    padding-top: 2px;}
.embeddedOutputsTextElement.inlineElement,.embeddedOutputsVariableStringElement.inlineElement {}
.inlineElement .textElement {}
.embeddedOutputsTextElement.rightPaneElement,.embeddedOutputsVariableStringElement.rightPaneElement {    min-height: 16px;}
.rightPaneElement .textElement {    padding-top: 2px;    padding-left: 9px;}
.S10 { border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 0px none rgb(33, 33, 33); border-radius: 0px; padding: 6px 45px 0px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }
.S11 { border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px 0px 4px 4px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px;  }</style></head><body><div class = rtcContent><h1  class = 'S0'><span>Example script how to use PIVlab from the commandline</span></h1><div  class = 'S1'><span>Just run this script to see what it does.</span></div><div  class = 'S1'><span>You can also adjust the settings in "s" and "p", specify a mask and a region of interest</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >clc; clear </span><span style="color: rgb(167, 9, 245);">variables</span><span >;close </span><span style="color: rgb(167, 9, 245);">all</span></span></div></div></div><div  class = 'S3'><span>Select a number &gt; 1 if you want to use the parallel computing toolbox to perform parallel computing:</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >nr_of_cores = 1; </span><span style="color: rgb(0, 128, 19);">% integer, 1 means single core, greater than 1 means parallel</span></span></div></div></div><div  class = 'S3'><span>Do some preparation for the parallel processing (if desired)</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">if </span><span >nr_of_cores &gt; 1</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">try</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		local_cluster=parcluster(</span><span style="color: rgb(167, 9, 245);">'local'</span><span >); </span><span style="color: rgb(0, 128, 19);">% single node</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		corenum =  local_cluster.NumWorkers ; </span><span style="color: rgb(0, 128, 19);">% fix : get the number of cores available</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">catch</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		warning(</span><span style="color: rgb(167, 9, 245);">'on'</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		warning(</span><span style="color: rgb(167, 9, 245);">'parallel local cluster can not be created, assigning number of cores to 1'</span><span >);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		nr_of_cores = 1;</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">end</span></span></div></div><div class="inlineWrapper"><div  class = 'S6'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">end</span></span></div></div></div><h2  class = 'S7'><span>Create list of images inside user specified directory</span></h2><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span >directory= [pwd filesep </span><span style="color: rgb(167, 9, 245);">'Examples'</span><span >] ; </span><span style="color: rgb(0, 128, 19);">%directory containing the images you want to analyze</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">% default directory: PIVlab/Examples</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >suffix=</span><span style="color: rgb(167, 9, 245);">'*.jpg'</span><span >; </span><span style="color: rgb(0, 128, 19);">%*.bmp or *.tif or *.jpg or *.tiff or *.jpeg</span></span></div></div><div class="inlineWrapper outputs"><div  class = 'S8'><span style="white-space: pre"><span >disp([</span><span style="color: rgb(167, 9, 245);">'Looking for ' </span><span >suffix </span><span style="color: rgb(167, 9, 245);">' files in the selected directory.'</span><span >]);</span></span></div><div  class = 'S9'><div class="inlineElement eoOutputWrapper embeddedOutputsTextElement" uid="DA7144FA" prevent-scroll="true" data-testid="output_0" style="width: 1139px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;"><div class="textElement eoOutputContent" data-previous-available-width="1109" data-previous-scroll-height="17" data-hashorizontaloverflow="false" style="max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;">Looking for *.jpg files in the selected directory.</div></div></div></div><div class="inlineWrapper"><div  class = 'S10'><span style="white-space: pre"><span >direc = dir([directory,filesep,suffix]); filenames={};</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >[filenames{1:length(direc),1}] = deal(direc.name);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >filenames = sortrows(filenames); </span><span style="color: rgb(0, 128, 19);">%sort all image files</span></span></div></div><div class="inlineWrapper"><div  class = 'S6'><span style="white-space: pre"><span >amount = length(filenames);</span></span></div></div></div><h2  class = 'S7'><span>Standard PIV Settings</span></h2><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span >s = cell(15,2); </span><span style="color: rgb(0, 128, 19);">% To make it more readable, let's create a "settings table"</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">%Parameter                          %Setting			%Options</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{1,1}= </span><span style="color: rgb(167, 9, 245);">'Int. area 1'</span><span >;              s{1,2}=64;			</span><span style="color: rgb(0, 128, 19);">% window size of first pass</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{2,1}= </span><span style="color: rgb(167, 9, 245);">'Step size 1'</span><span >;              s{2,2}=32;			</span><span style="color: rgb(0, 128, 19);">% step of first pass</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{3,1}= </span><span style="color: rgb(167, 9, 245);">'Subpix. finder'</span><span >;           s{3,2}=1;			</span><span style="color: rgb(0, 128, 19);">% 1 = 3point Gauss, 2 = 2D Gauss</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{4,1}= </span><span style="color: rgb(167, 9, 245);">'Mask'</span><span >;                     s{4,2}=[];			</span><span style="color: rgb(0, 128, 19);">% If needed, supply a binary image mask with the same size as the PIV images</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{5,1}= </span><span style="color: rgb(167, 9, 245);">'ROI'</span><span >;                      s{5,2}=[];			</span><span style="color: rgb(0, 128, 19);">% Region of interest: [x,y,width,height] in pixels, may be left empty to process the whole image</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{6,1}= </span><span style="color: rgb(167, 9, 245);">'Nr. of passes'</span><span >;            s{6,2}=2;			</span><span style="color: rgb(0, 128, 19);">% 1-4 nr. of passes</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{7,1}= </span><span style="color: rgb(167, 9, 245);">'Int. area 2'</span><span >;              s{7,2}=32;			</span><span style="color: rgb(0, 128, 19);">% second pass window size</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{8,1}= </span><span style="color: rgb(167, 9, 245);">'Int. area 3'</span><span >;              s{8,2}=16;			</span><span style="color: rgb(0, 128, 19);">% third pass window size</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{9,1}= </span><span style="color: rgb(167, 9, 245);">'Int. area 4'</span><span >;              s{9,2}=16;			</span><span style="color: rgb(0, 128, 19);">% fourth pass window size</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{10,1}=</span><span style="color: rgb(167, 9, 245);">'Window deformation'</span><span >;       s{10,2}=</span><span style="color: rgb(167, 9, 245);">'*linear'</span><span >;	</span><span style="color: rgb(0, 128, 19);">% '*spline' is more accurate, but slower</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{11,1}=</span><span style="color: rgb(167, 9, 245);">'Repeated Correlation'</span><span >;     s{11,2}=0;			</span><span style="color: rgb(0, 128, 19);">% 0 or 1 : Repeat the correlation four times and multiply the correlation matrices.</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{12,1}=</span><span style="color: rgb(167, 9, 245);">'Disable Autocorrelation'</span><span >;  s{12,2}=0;			</span><span style="color: rgb(0, 128, 19);">% 0 or 1 : Disable Autocorrelation in the first pass.</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{13,1}=</span><span style="color: rgb(167, 9, 245);">'Correlation style'</span><span >;        s{13,2}=0;			</span><span style="color: rgb(0, 128, 19);">% 0 or 1 : Use circular correlation (0) or linear correlation (1).</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >s{14,1}=</span><span style="color: rgb(167, 9, 245);">'Repeat last pass'</span><span >;			s{14,2}=0;			</span><span style="color: rgb(0, 128, 19);">% 0 or 1 : Repeat the last pass of a multipass analyis</span></span></div></div><div class="inlineWrapper"><div  class = 'S6'><span style="white-space: pre"><span >s{15,1}=</span><span style="color: rgb(167, 9, 245);">'Last pass quality slope'</span><span >;  s{15,2}=0.025;		</span><span style="color: rgb(0, 128, 19);">% Repetitions of last pass will stop when the average difference to the previous pass is less than this number.</span></span></div></div></div><h2  class = 'S7'><span>Standard image preprocessing settings</span></h2><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span >p = cell(10,1);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">%Parameter                       %Setting           %Options</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >p{1,1}= </span><span style="color: rgb(167, 9, 245);">'ROI'</span><span >;                   p{1,2}=s{5,2};     </span><span style="color: rgb(0, 128, 19);">% same as in PIV settings</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >p{2,1}= </span><span style="color: rgb(167, 9, 245);">'CLAHE'</span><span >;                 p{2,2}=1;          </span><span style="color: rgb(0, 128, 19);">% 1 = enable CLAHE (contrast enhancement), 0 = disable</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >p{3,1}= </span><span style="color: rgb(167, 9, 245);">'CLAHE size'</span><span >;            p{3,2}=50;         </span><span style="color: rgb(0, 128, 19);">% CLAHE window size</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >p{4,1}= </span><span style="color: rgb(167, 9, 245);">'Highpass'</span><span >;              p{4,2}=0;          </span><span style="color: rgb(0, 128, 19);">% 1 = enable highpass, 0 = disable</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >p{5,1}= </span><span style="color: rgb(167, 9, 245);">'Highpass size'</span><span >;         p{5,2}=15;         </span><span style="color: rgb(0, 128, 19);">% highpass size</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >p{6,1}= </span><span style="color: rgb(167, 9, 245);">'Clipping'</span><span >;              p{6,2}=0;          </span><span style="color: rgb(0, 128, 19);">% 1 = enable clipping, 0 = disable</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >p{7,1}= </span><span style="color: rgb(167, 9, 245);">'Wiener'</span><span >;                p{7,2}=0;          </span><span style="color: rgb(0, 128, 19);">% 1 = enable Wiener2 adaptive denoise filter, 0 = disable</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >p{8,1}= </span><span style="color: rgb(167, 9, 245);">'Wiener size'</span><span >;           p{8,2}=3;          </span><span style="color: rgb(0, 128, 19);">% Wiener2 window size</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >p{9,1}= </span><span style="color: rgb(167, 9, 245);">'Minimum intensity'</span><span >;     p{9,2}=0.0;        </span><span style="color: rgb(0, 128, 19);">% Minimum intensity of input image (0 = no change)</span></span></div></div><div class="inlineWrapper"><div  class = 'S6'><span style="white-space: pre"><span >p{10,1}=</span><span style="color: rgb(167, 9, 245);">'Maximum intensity'</span><span >;     p{10,2}=1.0;       </span><span style="color: rgb(0, 128, 19);">% Maximum intensity on input image (1 = no change)</span></span></div></div></div><h2  class = 'S7'><span>other settings</span></h2><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >pairwise = 1; </span><span style="color: rgb(0, 128, 19);">% 0 for [A+B], [B+C], [C+D]... sequencing style, and 1 for [A+B], [C+D], [E+F]... sequencing style</span></span></div></div></div><h2  class = 'S7'><span>PIV analysis loop</span></h2><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">if </span><span >pairwise == 1</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">if </span><span >mod(amount,2) == 1 </span><span style="color: rgb(0, 128, 19);">%Uneven number of images?</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		disp(</span><span style="color: rgb(167, 9, 245);">'Image folder should contain an even number of images.'</span><span >)</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		</span><span style="color: rgb(0, 128, 19);">%remove last image from list</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		amount=amount-1;</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		filenames(size(filenames,1))=[];</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">end</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	disp([</span><span style="color: rgb(167, 9, 245);">'Found ' </span><span >num2str(amount) </span><span style="color: rgb(167, 9, 245);">' images (' </span><span >num2str(amount/2) </span><span style="color: rgb(167, 9, 245);">' image pairs).'</span><span >])</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	x=cell(amount/2,1);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	y=x;</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	u=x;</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	v=x;</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">else</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	disp([</span><span style="color: rgb(167, 9, 245);">'Found ' </span><span >num2str(amount) </span><span style="color: rgb(167, 9, 245);">' images'</span><span >])</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	x=cell(amount-1,1);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	y=x;</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	u=x;</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	v=x;</span></span></div></div><div class="inlineWrapper outputs"><div  class = 'S8'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">end</span></span></div><div  class = 'S9'><div class="inlineElement eoOutputWrapper embeddedOutputsTextElement" uid="A25C2096" prevent-scroll="true" data-testid="output_1" style="width: 1139px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;"><div class="textElement eoOutputContent" data-previous-available-width="1109" data-previous-scroll-height="17" data-hashorizontaloverflow="false" style="max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;">Found 20 images (10 image pairs).</div></div></div></div><div class="inlineWrapper"><div  class = 'S10'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >typevector=x; </span><span style="color: rgb(0, 128, 19);">%typevector will be 1 for regular vectors, 0 for masked areas</span></span></div></div><div class="inlineWrapper"><div  class = 'S6'><span style="white-space: pre"><span >correlation_map=x; </span><span style="color: rgb(0, 128, 19);">% correlation coefficient</span></span></div></div></div><h2  class = 'S7'><span>Pre-load the image names out side of the parallelizable loop</span></h2><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span >slicedfilename1=cell(0);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >slicedfilename2=cell(0);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >j = 1;</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">for </span><span >i=1:1+pairwise:amount-1</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	slicedfilename1{j}=filenames{i}; </span><span style="color: rgb(0, 128, 19);">% begin</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	slicedfilename2{j}=filenames{i+1}; </span><span style="color: rgb(0, 128, 19);">% end</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	j = j+1;</span></span></div></div><div class="inlineWrapper"><div  class = 'S6'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">end</span></span></div></div></div><h2  class = 'S7'><span>Main PIV analysis loop:</span></h2><div  class = 'S1'><span>Parallel processing or...</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">if </span><span >nr_of_cores &gt; 1</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">if </span><span >pivparpool(</span><span style="color: rgb(167, 9, 245);">'size'</span><span >)&lt;nr_of_cores</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		pivparpool(</span><span style="color: rgb(167, 9, 245);">'open'</span><span >,nr_of_cores);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">end</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">parfor </span><span >i=1:size(slicedfilename1,2)  </span><span style="color: rgb(0, 128, 19);">% index must increment by 1</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		[x{i}, y{i}, u{i}, v{i}, typevector{i},correlation_map{i}] = </span><span style="color: rgb(14, 0, 255);">...</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >			piv_analysis(directory, slicedfilename1{i}, slicedfilename2{i},p,s,nr_of_cores,false);</span></span></div></div><div class="inlineWrapper"><div  class = 'S6'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">end</span></span></div></div></div><div  class = 'S3'><span>... Sequential loop</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">else </span><span style="color: rgb(0, 128, 19);">% sequential loop</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">for </span><span >i=1:size(slicedfilename1,2)  </span><span style="color: rgb(0, 128, 19);">% index must increment by 1</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		[x{i}, y{i}, u{i}, v{i}, typevector{i},correlation_map{i}] = </span><span style="color: rgb(14, 0, 255);">...</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >			piv_analysis(directory, slicedfilename1{i}, slicedfilename2{i},p,s,nr_of_cores,true);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		disp([int2str((i+1)/amount*100) </span><span style="color: rgb(167, 9, 245);">' %'</span><span >]);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">end</span></span></div></div><div class="inlineWrapper outputs"><div  class = 'S8'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">end</span></span></div><div  class = 'S9'><div class="inlineElement eoOutputWrapper embeddedOutputsTextElement" uid="47F1AB86" prevent-scroll="true" data-testid="output_2" style="width: 1139px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;"><div class="textElement eoOutputContent" data-previous-available-width="1109" data-previous-scroll-height="135" data-hashorizontaloverflow="false" style="max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;">10 %
15 %
20 %
25 %
30 %
35 %
40 %
45 %
50 %</div></div><div class="inlineElement eoOutputWrapper embeddedOutputsFigure" uid="914085DE" prevent-scroll="true" data-testid="output_3" style="width: 1139px;"><div class="figureElement eoOutputContent"><img class="figureImage figureContainingNode" src="" style="width: 560px; padding-bottom: 0px;"></div><div class="outputLayer selectedOutputDecorationLayer doNotExport"></div><div class="outputLayer activeOutputDecorationLayer doNotExport"></div><div class="outputLayer scrollableOutputDecorationLayer doNotExport"></div></div><div class="inlineElement eoOutputWrapper embeddedOutputsTextElement" uid="606A3DE6" prevent-scroll="true" data-testid="output_4" style="width: 1139px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;"><div class="textElement eoOutputContent" data-previous-available-width="1109" data-previous-scroll-height="17" data-hashorizontaloverflow="false" style="max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;">55 %</div></div></div></div><div class="inlineWrapper"><div  class = 'S11'>&nbsp;</div></div></div><div  class = 'S3'><span>The most important results are x,y,u,v. These can now be viewed before validation:</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span >figure;quiver(x{1},y{1},u{1},v{1},5);axis </span><span style="color: rgb(167, 9, 245);">image</span><span >;  </span><span style="color: rgb(0, 128, 19);">%(the last number determines the displayed sclae of the vectors)</span></span></div></div><div class="inlineWrapper outputs"><div  class = 'S8'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">'Raw results of first image pair'</span><span >)</span></span></div><div  class = 'S9'><div class="inlineElement eoOutputWrapper embeddedOutputsFigure" uid="19DF96CC" prevent-scroll="true" data-testid="output_5" style="width: 1139px;"><div class="figureElement eoOutputContent"><img class="figureImage figureContainingNode" src="" style="width: 560px; padding-bottom: 0px;"></div><div class="outputLayer selectedOutputDecorationLayer doNotExport"></div><div class="outputLayer activeOutputDecorationLayer doNotExport"></div><div class="outputLayer scrollableOutputDecorationLayer doNotExport"></div></div></div></div></div><h2  class = 'S7'><span>PIV postprocessing loop</span></h2><div  class = 'S1'><span>Standard image post processing settings</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span >r = cell(6,1);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">%Parameter     %Setting                                     %Options</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >r{1,1}= </span><span style="color: rgb(167, 9, 245);">'Calibration factor, 1 for uncalibrated data'</span><span >;      r{1,2}=1;                   </span><span style="color: rgb(0, 128, 19);">% Calibration factor for u</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >r{2,1}= </span><span style="color: rgb(167, 9, 245);">'Calibration factor, 1 for uncalibrated data'</span><span >;      r{2,2}=1;                   </span><span style="color: rgb(0, 128, 19);">% Calibration factor for v</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >r{3,1}= </span><span style="color: rgb(167, 9, 245);">'Valid velocities [u_min; u_max; v_min; v_max]'</span><span >;    r{3,2}=[-50; 50; -50; 50];  </span><span style="color: rgb(0, 128, 19);">% Maximum allowed velocities, for uncalibrated data: maximum displacement in pixels</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >r{4,1}= </span><span style="color: rgb(167, 9, 245);">'Stdev check?'</span><span >;                                     r{4,2}=1;                   </span><span style="color: rgb(0, 128, 19);">% 1 = enable global standard deviation test</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >r{5,1}= </span><span style="color: rgb(167, 9, 245);">'Stdev threshold'</span><span >;                                  r{5,2}=7;                   </span><span style="color: rgb(0, 128, 19);">% Threshold for the stdev test</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >r{6,1}= </span><span style="color: rgb(167, 9, 245);">'Local median check?'</span><span >;                              r{6,2}=1;                   </span><span style="color: rgb(0, 128, 19);">% 1 = enable local median test</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >r{7,1}= </span><span style="color: rgb(167, 9, 245);">'Local median threshold'</span><span >;                           r{7,2}=3;                   </span><span style="color: rgb(0, 128, 19);">% Threshold for the local median test</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >u_filt=cell(size(u));</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >v_filt=cell(size(v));</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >typevector_filt=typevector;</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">if </span><span >nr_of_cores &gt;1 </span><span style="color: rgb(0, 128, 19);">% parallel loop</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">if </span><span >pivparpool(</span><span style="color: rgb(167, 9, 245);">'size'</span><span >)&lt;nr_of_cores</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		pivparpool(</span><span style="color: rgb(167, 9, 245);">'open'</span><span >,nr_of_cores);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">end</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">parfor </span><span >PIVresult=1:size(x,1)</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		[u_filt{PIVresult,1}, v_filt{PIVresult,1},typevector_filt{PIVresult,1}]= </span><span style="color: rgb(14, 0, 255);">...</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >			post_proc_wrapper(u{PIVresult,1},v{PIVresult,1},typevector{PIVresult,1},r,true);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">end</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">else </span><span style="color: rgb(0, 128, 19);">% sequential loop</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">for </span><span >PIVresult=1:size(x,1)</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >		[u_filt{PIVresult,1}, v_filt{PIVresult,1},typevector_filt{PIVresult,1}]= </span><span style="color: rgb(14, 0, 255);">...</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >			post_proc_wrapper(u{PIVresult,1},v{PIVresult,1},typevector{PIVresult,1},r,true);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	</span><span style="color: rgb(14, 0, 255);">end</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S6'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">end</span></span></div></div></div><div  class = 'S3'><span>Post-processing finished, here are the filtered results:</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span >figure;quiver(x{1},y{1},u_filt{1},v_filt{1},5);axis </span><span style="color: rgb(167, 9, 245);">image</span><span >; </span><span style="color: rgb(0, 128, 19);">%(the last number determines the displayed sclae of the vectors)</span></span></div></div><div class="inlineWrapper outputs"><div  class = 'S8'><span style="white-space: pre"><span >title(</span><span style="color: rgb(167, 9, 245);">'Filtered results of first image pair'</span><span >)</span></span></div><div  class = 'S9'><div class="inlineElement eoOutputWrapper embeddedOutputsFigure" uid="40FB3F1F" prevent-scroll="true" data-testid="output_6" style="width: 1139px;"><div class="figureElement eoOutputContent"><img class="figureImage figureContainingNode" src="" style="width: 560px; padding-bottom: 0px;"></div><div class="outputLayer selectedOutputDecorationLayer doNotExport"></div><div class="outputLayer activeOutputDecorationLayer doNotExport"></div><div class="outputLayer scrollableOutputDecorationLayer doNotExport"></div></div></div></div></div><h2  class = 'S7'><span>clean up parallel pool, and cluster (if required, will save RAM)</span></h2><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">%{</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">if nr_of_cores &gt;1 % parallel</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">	poolobj = gcp('nocreate'); % GET the current parallel pool</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">	if ~isempty(poolobj ); delete(poolobj );end</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">	clear local_cluster;</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">end</span></span></div></div><div class="inlineWrapper"><div  class = 'S6'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">%}</span></span></div></div></div><div  class = 'S1'><span>Save the data to a Matlab file</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S2'><span style="white-space: pre"><span >save(fullfile(directory, [filenames{1} </span><span style="color: rgb(167, 9, 245);">'_' </span><span >filenames{end} </span><span style="color: rgb(167, 9, 245);">'_' </span><span >num2str(amount) </span><span style="color: rgb(167, 9, 245);">'_frames_result_.mat'</span><span >]));</span></span></div></div></div><div  class = 'S1'><span>Clean up unused vars</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span >clearvars </span><span style="color: rgb(167, 9, 245);">-except p s r x y u v typevector directory filenames u_filt v_filt typevector_filt correlation_map</span></span></div></div><div class="inlineWrapper outputs"><div  class = 'S8'><span style="white-space: pre"><span >disp(</span><span style="color: rgb(167, 9, 245);">'DONE.'</span><span >)</span></span></div><div  class = 'S9'><div class="inlineElement eoOutputWrapper embeddedOutputsTextElement" uid="02BFF023" prevent-scroll="true" data-testid="output_7" style="width: 1139px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;"><div class="textElement eoOutputContent" data-previous-available-width="1109" data-previous-scroll-height="17" data-hashorizontaloverflow="false" style="max-height: 261px; white-space: pre; font-style: normal; color: rgb(33, 33, 33); font-size: 12px;">DONE.</div></div></div></div><div class="inlineWrapper"><div  class = 'S11'>&nbsp;</div></div></div><div  class = 'S1'><span>Wrapper function for PIVlab_postproc</span></div><div class="CodeBlock"><div class="inlineWrapper"><div  class = 'S4'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">function </span><span >[u_filt, v_filt,typevector_filt] = post_proc_wrapper(u,v,typevector,post_proc_setting,paint_nan)</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">% wrapper function for PIVlab_postproc</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">% INPUT</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">% u, v: u and v components of vector fields</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">% typevector: type vector</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">% post_proc_setting: post processing setting</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">% paint_nan: bool, whether to interpolate missing data</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">% OUTPUT</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">% u_filt, v_filt: post-processed u and v components of vector fields</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(0, 128, 19);">% typevector_filt: post-processed type vector</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >[u_filt,v_filt] = PIVlab_postproc(u,v, </span><span style="color: rgb(14, 0, 255);">...</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	post_proc_setting{1,2},</span><span style="color: rgb(14, 0, 255);">...</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	post_proc_setting{2,2},</span><span style="color: rgb(14, 0, 255);">...</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	post_proc_setting{3,2},</span><span style="color: rgb(14, 0, 255);">...</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	post_proc_setting{4,2},</span><span style="color: rgb(14, 0, 255);">...</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	post_proc_setting{5,2},</span><span style="color: rgb(14, 0, 255);">...</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	post_proc_setting{6,2},</span><span style="color: rgb(14, 0, 255);">...</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	post_proc_setting{7,2});</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >typevector_filt = typevector; </span><span style="color: rgb(0, 128, 19);">% initiate</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >typevector_filt(isnan(u_filt))=2;</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >typevector_filt(isnan(v_filt))=2;</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >typevector_filt(typevector==0)=0; </span><span style="color: rgb(0, 128, 19);">%restores typevector for mask</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">if </span><span >paint_nan</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	u_filt=inpaint_nans(u_filt,4);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span >	v_filt=inpaint_nans(v_filt,4);</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">end</span></span></div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S5'>&nbsp;</div></div><div class="inlineWrapper"><div  class = 'S6'><span style="white-space: pre"><span style="color: rgb(14, 0, 255);">end</span></span></div></div></div>
<br>
<!-- 
##### SOURCE BEGIN #####
%% Example script how to use PIVlab from the commandline
% Just run this script to see what it does.
% 
% You can also adjust the settings in "s" and "p", specify a mask and a region 
% of interest

clc; clear variables;close all
%% 
% Select a number > 1 if you want to use the parallel computing toolbox to perform 
% parallel computing:

nr_of_cores = 1; % integer, 1 means single core, greater than 1 means parallel
%% 
% Do some preparation for the parallel processing (if desired)

if nr_of_cores > 1
	try
		local_cluster=parcluster('local'); % single node
		corenum =  local_cluster.NumWorkers ; % fix : get the number of cores available
	catch
		warning('on');
		warning('parallel local cluster can not be created, assigning number of cores to 1');
		nr_of_cores = 1;
	end
end
%% Create list of images inside user specified directory

directory= [pwd filesep 'Examples'] ; %directory containing the images you want to analyze
% default directory: PIVlab/Examples

suffix='*.jpg'; %*.bmp or *.tif or *.jpg or *.tiff or *.jpeg
disp(['Looking for ' suffix ' files in the selected directory.']);
direc = dir([directory,filesep,suffix]); filenames={};
[filenames{1:length(direc),1}] = deal(direc.name);
filenames = sortrows(filenames); %sort all image files
amount = length(filenames);
%% Standard PIV Settings

s = cell(15,2); % To make it more readable, let's create a "settings table"
%Parameter                          %Setting			%Options
s{1,1}= 'Int. area 1';              s{1,2}=64;			% window size of first pass
s{2,1}= 'Step size 1';              s{2,2}=32;			% step of first pass
s{3,1}= 'Subpix. finder';           s{3,2}=1;			% 1 = 3point Gauss, 2 = 2D Gauss
s{4,1}= 'Mask';                     s{4,2}=[];			% If needed, supply a binary image mask with the same size as the PIV images
s{5,1}= 'ROI';                      s{5,2}=[];			% Region of interest: [x,y,width,height] in pixels, may be left empty to process the whole image
s{6,1}= 'Nr. of passes';            s{6,2}=2;			% 1-4 nr. of passes
s{7,1}= 'Int. area 2';              s{7,2}=32;			% second pass window size
s{8,1}= 'Int. area 3';              s{8,2}=16;			% third pass window size
s{9,1}= 'Int. area 4';              s{9,2}=16;			% fourth pass window size
s{10,1}='Window deformation';       s{10,2}='*linear';	% '*spline' is more accurate, but slower
s{11,1}='Repeated Correlation';     s{11,2}=0;			% 0 or 1 : Repeat the correlation four times and multiply the correlation matrices.
s{12,1}='Disable Autocorrelation';  s{12,2}=0;			% 0 or 1 : Disable Autocorrelation in the first pass.
s{13,1}='Correlation style';        s{13,2}=0;			% 0 or 1 : Use circular correlation (0) or linear correlation (1).
s{14,1}='Repeat last pass';			s{14,2}=0;			% 0 or 1 : Repeat the last pass of a multipass analyis
s{15,1}='Last pass quality slope';  s{15,2}=0.025;		% Repetitions of last pass will stop when the average difference to the previous pass is less than this number.
%% Standard image preprocessing settings

p = cell(10,1);
%Parameter                       %Setting           %Options
p{1,1}= 'ROI';                   p{1,2}=s{5,2};     % same as in PIV settings
p{2,1}= 'CLAHE';                 p{2,2}=1;          % 1 = enable CLAHE (contrast enhancement), 0 = disable
p{3,1}= 'CLAHE size';            p{3,2}=50;         % CLAHE window size
p{4,1}= 'Highpass';              p{4,2}=0;          % 1 = enable highpass, 0 = disable
p{5,1}= 'Highpass size';         p{5,2}=15;         % highpass size
p{6,1}= 'Clipping';              p{6,2}=0;          % 1 = enable clipping, 0 = disable
p{7,1}= 'Wiener';                p{7,2}=0;          % 1 = enable Wiener2 adaptive denoise filter, 0 = disable
p{8,1}= 'Wiener size';           p{8,2}=3;          % Wiener2 window size
p{9,1}= 'Minimum intensity';     p{9,2}=0.0;        % Minimum intensity of input image (0 = no change)
p{10,1}='Maximum intensity';     p{10,2}=1.0;       % Maximum intensity on input image (1 = no change)
%% other settings

pairwise = 1; % 0 for [A+B], [B+C], [C+D]... sequencing style, and 1 for [A+B], [C+D], [E+F]... sequencing style
%% PIV analysis loop

if pairwise == 1
	if mod(amount,2) == 1 %Uneven number of images?
		disp('Image folder should contain an even number of images.')
		%remove last image from list
		amount=amount-1;
		filenames(size(filenames,1))=[];
	end

	disp(['Found ' num2str(amount) ' images (' num2str(amount/2) ' image pairs).'])
	x=cell(amount/2,1);
	y=x;
	u=x;
	v=x;
else
	disp(['Found ' num2str(amount) ' images'])
	x=cell(amount-1,1);
	y=x;
	u=x;
	v=x;
end

typevector=x; %typevector will be 1 for regular vectors, 0 for masked areas
correlation_map=x; % correlation coefficient
%% Pre-load the image names out side of the parallelizable loop

slicedfilename1=cell(0);
slicedfilename2=cell(0);
j = 1;
for i=1:1+pairwise:amount-1
	slicedfilename1{j}=filenames{i}; % begin
	slicedfilename2{j}=filenames{i+1}; % end
	j = j+1;
end
%% Main PIV analysis loop:
% Parallel processing or...

if nr_of_cores > 1
	if pivparpool('size')<nr_of_cores
		pivparpool('open',nr_of_cores);
	end

	parfor i=1:size(slicedfilename1,2)  % index must increment by 1

		[x{i}, y{i}, u{i}, v{i}, typevector{i},correlation_map{i}] = ...
			piv_analysis(directory, slicedfilename1{i}, slicedfilename2{i},p,s,nr_of_cores,false);
	end
%% 
% ... Sequential loop

else % sequential loop

	for i=1:size(slicedfilename1,2)  % index must increment by 1

		[x{i}, y{i}, u{i}, v{i}, typevector{i},correlation_map{i}] = ...
			piv_analysis(directory, slicedfilename1{i}, slicedfilename2{i},p,s,nr_of_cores,true);

		disp([int2str((i+1)/amount*100) ' %']);

	end
end

%% 
% The most important results are x,y,u,v. These can now be viewed before validation:

figure;quiver(x{1},y{1},u{1},v{1},5);axis image;  %(the last number determines the displayed sclae of the vectors)
title('Raw results of first image pair')
%% PIV postprocessing loop
% Standard image post processing settings

r = cell(6,1);
%Parameter     %Setting                                     %Options
r{1,1}= 'Calibration factor, 1 for uncalibrated data';      r{1,2}=1;                   % Calibration factor for u
r{2,1}= 'Calibration factor, 1 for uncalibrated data';      r{2,2}=1;                   % Calibration factor for v
r{3,1}= 'Valid velocities [u_min; u_max; v_min; v_max]';    r{3,2}=[-50; 50; -50; 50];  % Maximum allowed velocities, for uncalibrated data: maximum displacement in pixels
r{4,1}= 'Stdev check?';                                     r{4,2}=1;                   % 1 = enable global standard deviation test
r{5,1}= 'Stdev threshold';                                  r{5,2}=7;                   % Threshold for the stdev test
r{6,1}= 'Local median check?';                              r{6,2}=1;                   % 1 = enable local median test
r{7,1}= 'Local median threshold';                           r{7,2}=3;                   % Threshold for the local median test

u_filt=cell(size(u));
v_filt=cell(size(v));
typevector_filt=typevector;

if nr_of_cores >1 % parallel loop

	if pivparpool('size')<nr_of_cores
		pivparpool('open',nr_of_cores);
	end

	parfor PIVresult=1:size(x,1)

		[u_filt{PIVresult,1}, v_filt{PIVresult,1},typevector_filt{PIVresult,1}]= ...
			post_proc_wrapper(u{PIVresult,1},v{PIVresult,1},typevector{PIVresult,1},r,true);

	end

else % sequential loop

	for PIVresult=1:size(x,1)

		[u_filt{PIVresult,1}, v_filt{PIVresult,1},typevector_filt{PIVresult,1}]= ...
			post_proc_wrapper(u{PIVresult,1},v{PIVresult,1},typevector{PIVresult,1},r,true);

	end

end
%% 
% Post-processing finished, here are the filtered results:

figure;quiver(x{1},y{1},u_filt{1},v_filt{1},5);axis image; %(the last number determines the displayed sclae of the vectors)
title('Filtered results of first image pair')
%% clean up parallel pool, and cluster (if required, will save RAM)

%{
if nr_of_cores >1 % parallel
	poolobj = gcp('nocreate'); % GET the current parallel pool
	if ~isempty(poolobj ); delete(poolobj );end
	clear local_cluster;
end
%}
%% 
% Save the data to a Matlab file

save(fullfile(directory, [filenames{1} '_' filenames{end} '_' num2str(amount) '_frames_result_.mat']));
%% 
% Clean up unused vars

clearvars -except p s r x y u v typevector directory filenames u_filt v_filt typevector_filt correlation_map
disp('DONE.')

%% 
% Wrapper function for PIVlab_postproc

function [u_filt, v_filt,typevector_filt] = post_proc_wrapper(u,v,typevector,post_proc_setting,paint_nan)
% wrapper function for PIVlab_postproc

% INPUT
% u, v: u and v components of vector fields
% typevector: type vector
% post_proc_setting: post processing setting
% paint_nan: bool, whether to interpolate missing data

% OUTPUT
% u_filt, v_filt: post-processed u and v components of vector fields
% typevector_filt: post-processed type vector


[u_filt,v_filt] = PIVlab_postproc(u,v, ...
	post_proc_setting{1,2},...
	post_proc_setting{2,2},...
	post_proc_setting{3,2},...
	post_proc_setting{4,2},...
	post_proc_setting{5,2},...
	post_proc_setting{6,2},...
	post_proc_setting{7,2});

typevector_filt = typevector; % initiate
typevector_filt(isnan(u_filt))=2;
typevector_filt(isnan(v_filt))=2;
typevector_filt(typevector==0)=0; %restores typevector for mask

if paint_nan
	u_filt=inpaint_nans(u_filt,4);
	v_filt=inpaint_nans(v_filt,4);
end


end
##### SOURCE END #####
-->
</div></body></html>